﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectCloth.Entity
{
    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    public class ClothContext : DbContext
    {
        public static string connection = "";//"Data Source=212.64.54.64;port=3306;Initial Catalog=clothdbtest;uid=root;password=root@cloth;Charset=utf8";
        public Color BackgroudColor = Color.LightBlue;
        public string GetFloor()
        {
            if (connection.Contains("0401")|| connection.Contains("1224"))
            {
                BackgroudColor = Color.LightBlue;
                return "---一楼";
            }
            else
            {
                BackgroudColor = Color.LightGreen;
                return
                 "---三楼";
            }
        }
#if DEBUG
        public ClothContext() : base(connection)
        //: base("Data Source=212.64.54.64;port=3306;Initial Catalog=clothdb0401;uid=root;password=root@cloth;Charset=utf8")
        {
            Database.SetInitializer<ClothContext>(null);
            //Database.SetInitializer(new MigrateDatabaseToLatestVersion<ClothContext, Migrations.Configuration>());
            //Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ClothContext>());
        }
#else
        string connectStr = @"Data Source=120.79.155.81;port=3306;Initial Catalog=clothdb0402;uid=root;password=root@cloth;Charset=utf8";
        //string dbselect = ConfigurationManager.AppSettings["db"].ToString();
        //if(dbselect=="2")
        //{
        //connectStr=@"Data Source=120.79.155.81;port=3306;Initial Catalog=clothdb0402;uid=root;password=root@cloth;Charset=utf8";
        //};
        public ClothContext()
            : base("Data Source = 120.79.155.81; port=3306;Initial Catalog = clothdb0402; uid=root;password=root @cloth; Charset=utf8")
        {
            Database.SetInitializer<ClothContext>(null);

        }
#endif
        //public ClothContext(string Default)
        //    : base(Default)
        //{
        //    Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ClothContext>());
        //}
        public DbSet<User> Users { get; set; }//用户
        public DbSet<Role> Roles { get; set; }//角色
        public DbSet<Permission> Permissions { get; set; }//权限 
        public DbSet<LoginLog> LoginLogs { get; set; }
        public DbSet<SystemInfo> SystemInfos { get; set; }

        public DbSet<Company> Companies { get; set; }//企业单位
        //public DbSet<Department> Departments { get; set; }//部门
        public DbSet<Product> Products { get; set; }//商品
        public DbSet<InStockProduct> InStockProducts { get; set; }//进货
        public DbSet<SaleOrder> SaleOrders { get; set; }//销售单
        public DbSet<SaleOrderItem> SaleOrderItems { get; set; }//销售单详细
        public DbSet<InStockItem> InStockItems { get; set; }
        //public DbSet<TradeType> TradeTypes { get; set; }
        public DbSet<GeneralExpenses> GeneralExpenseses { get; set; }
        public DbSet<GeneralExpensesItem> GeneralExpensesItems { get; set; }
        public DbSet<Subject> Subjects { get; set; }
        public DbSet<PickupGoods> PickupGoodses { get; set; }
        public DbSet<CashAccount> CashAccounts { get; set; }
        public DbSet<CashAccountLog> CashAccountLogs { get; set; }
        public DbSet<PayableAccount> PayableAccounts { get; set; }
        public DbSet<ReceivableAccount> ReceivableAccounts { get; set; }
        public DbSet<ColorCard> ColorCards { get; set; }
        public DbSet<ReceivableAccountItem> ReceivableAccountItems { get; set; }
        //2020-2-1 添加
        public DbSet<DraftOrder> DraftOrders { get; set; }
        public DbSet<DraftOrderItem> DraftOrderItems { get; set; }
        public DbSet<AskPriceOrder> AskPriceOrders { get; set; }
        public DbSet<OnSaleProduct> OnSaleProducts { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }
    }
}
